package com.woniu.controller;

import com.woniu.service.OperatePaperService;
import com.woniuxy.commons.entity.TestPaper;
import com.woniuxy.commons.entity.TestQuestion;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @program: bzeducation
 * @author: Xingqilin
 * @create: 2020-07-23 17:33
 * @description: 试卷操作类
 */
@RestController
@RequestMapping("/operatePaper")
public class OperatePaperController {

    @Resource
    OperatePaperService operatePaperService;

    @PostMapping("/insertPaper")
    public long insertPaper(@RequestBody TestPaper testPaper) {
        System.out.println(testPaper);
        return operatePaperService.generatePaper(testPaper);
    }

    @RequestMapping(value = "/updatePaper", method = RequestMethod.PUT)
    public int updatePaper(@RequestBody TestPaper testPaper) {
        int i = operatePaperService.updatePaper(testPaper);
        return i;
    }

    @RequestMapping(value = "/deletePaper/{paperId}", method = RequestMethod.DELETE)
    public int deletePaper(@PathVariable Long paperId) {
        int i = operatePaperService.deletePaper(paperId);
        return i;
    }

    @RequestMapping(value = "/generatePaper", method = RequestMethod.POST)
    public long generatePaper(@RequestBody TestPaper testPaper) {
        long paperId = operatePaperService.generatePaper(testPaper);
        return paperId;
    }

    @RequestMapping(value = "/insertQuestion", method = RequestMethod.POST)
    public HashMap<String, Object> insertQuestions(@RequestBody List<TestQuestion> testQuestions) {
        HashMap<String, Object> msg = new HashMap<>();
        testQuestions.forEach(System.out::println);
        operatePaperService.insertQuestion(testQuestions);
        return msg;
    }
}
